import numpy as np
def bin_search(seq, target, is_return_none=False):
    n = len(seq)
    left, right = 0, n - 1
    while left < right - 1:
        idx = (right - left) // 2 + left
        if seq[idx] == target:
            return idx
        elif seq[idx] < target:
            left = idx
        else:
            right = idx
    if is_return_none:
        return None
    else:
        return left
def seek_in_mat(mat, target):
    mat_np = np.array(mat, dtype=int)
    heads = mat_np[:, 0]
    idx_row = bin_search(heads, target)
    row = mat_np[idx_row]
    idx_col = bin_search(row, target, is_return_none=True)
    return idx_col
if __name__ == '__main__':
    mat01 = [
        [1, 3, 5, 7],
        [10, 11, 16, 20],
        [23, 30, 34, 60]
    ]
    print(seek_in_mat(mat01, 3))
    print(seek_in_mat(mat01, 13))
